home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sun Solutions 1997 April to September
/
Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso
/
products
/
.wais
/
Solaris_2
/
dbdump.pl
< prev
next >
Wrap
Perl Script
|
1996-09-05
|
11KB
|
456 lines
#!/net/tenerife/opt/PUBperl5/bin/perl5
# /export/scratch/illustra/bin/perl5
# /opt/PUBperl5/bin/perl5
#
# makedesc.pl
#
# Generate The Wais Tree
#
# Copyright Creative Dynamics, Inc. 1995
#
#$dirn = $0;
#$dirn =~ s#(.*)/.*$#$1#;
#require "$dirn/common.pl";
$CATDB_NAME = "catalyst";
$USER = "miadmin";
$HOST = "localhost:7999";
$HTML = ".wais/Catalog.html";
$HOMEHTML = "SunSolutions/index.html";
#
# use the libmi stuff
#
use Mi;
$lastCategory = "";
$lastSubCategory = "";
$newchapter = 0;
### Set up output directory
$outputDirectory = "/net/snl/cdware/CDware/.products/.wais/wais-src";
umask(022);
mkdir($outputDirectory, 0777); # make an output directory for book
chdir "$outputDirectory" || die "Can't cd to $outputDirectory\n";
unlink(<*>); # delete all existing files in the output directory
{
local($query,$num_col, @record);
local($db, $row_desc, $result, $row, $col, $row_num, $error);
### the query
$query = "
select p.Product_id, p.SolCompatible,
p.ProdCatName, p.ProdSubCat, p.ProdName, v.VendorName,
p.ProdShortDesc, p.ProdLongDesc,
p.ProdHomePage, p.ProdImage, p.SrcAvail, p.ProdSrcLang,
p.ProdSpecHand,
v.VendorAddr1, v.VendorAddr2, v.VendorAddr3, v.VendorCity,
v.VendorPostCode,
v.VendorState, v.VendorZip, v.VendorCountry,
v.VendorPhone1code, v.VendorPhone1,
v.VendorPhone2code, v.VendorPhone2,
v.VendorFaxCode, v.VendorFax,
v.VendorEmailCode, v.VendorEmail,
v.VendorURL
from Vendor v using(lock=table),
Assoc_ProdVend a using(lock=table),
Products p using(lock=table)
where a.ProdId = p.Product_id
and a.VendId = v.Vendor_id
order by p.ProdCatName, p.ProdSubCat, p.ProdName
;";
# where p.Product_id < 100 -- use to limit
# alternate order: order by p.ProdCatName, p.ProdSubCat, p.ProdName, v.VendorName
### query the database
($db = Mi::open("$CATDB_NAME", "$USER", "") ) || die "Can't open Illustra database\n";
(Mi::exec($db, "$query", 0) == 0) || die "Can't exec Illustra query\n";
print " Query Sent\n";
(($result = Mi::get_result($db)) == 1) || die "Got bad result from Illustra\n";
print " Got Results\n";
($row_desc = Mi::get_row_desc_without_row($db)) || die "Error on row description \n";
$num_col = Mi::column_count($row_desc);
print " Results Have $num_col Columns\n";
$row_num = 0;
while ($row = Mi::next_row($db, \$error))
{
$row_num++;
print " Processing row $row_num...\r";
foreach $col (0..$num_col-1)
{
Mi::value($row, $col, $colval, $retlen);
$record[$col] = $colval;
}
### Fix the data
# map double occurrences of ' to single '
foreach $count (2..12)
{
$record[$count] =~ s/\'\'/\'/g;
}
### Trim trailing spaces
foreach $count (2..30)
{
$record[$count] =~ s/ *$//g;
}
### Fix descriptions
$record[7] = ($record[7] =~ /\S/) ? $record[7] : $record[6];
if ($record[7] eq "")
{
$record[7] = $record[6];
}
&makeBullets();
### Now print out the data for this product
$newchapter = 0;
if ($lastCategory ne $record[2])
{
chdir $outputDirectory || die "bad cd\n";
$newchapter = 1;
$outputChapterName = &fix_special($record[2]);
$outputChapterName = &makefilename($outputChapterName, 25);
mkdir($outputChapterName, 0777);
chdir "$outputChapterName" || die "Can't cd to $outputChapterName\n";
unlink(<*>);
$lastCategory = $record[2];
$subTOCname = $outputChapterName . ".html";
open(subTOC, "> $subTOCname");
&addsubTOCheader($record[2]);
}
if ($lastSubCategory ne $record[3])
{
if ($record[3] eq "")
{
$record[3] = "NoSubcategory";
}
if ($newchapter == 0)
{
chdir ".." || die "bad sub cd\n";
}
$outputSubchapterName = &fix_special($record[3]);
$outputSubchapterName = &makefilename($outputSubchapterName, 25);
mkdir($outputSubchapterName, 0777);
chdir $outputSubchapterName || die "Can't cd to $outputSubchapterName\n";
unlink(<*>);
$lastSubCategory = $record[3];
$TOCname = $outputSubchapterName . ".html";
open(TOC, "> $TOCname");
&makeTOCheader($subTOCname, $record[2], $record[3]);
chdir("..") || die "Can't cd to main category";
&addsubTOC($record[3], $outputSubchapterName);
chdir "$outputSubchapterName" || die "Can't cd to subcategory";
}
$filename = &fix_special($record[4]);
$filename = &makefilename($filename, 25);
$filename .= ".html";
open(PRODUCT, ">$filename") || die "Can't open product $filename\n";
&makeproductheader($record[3], $outputChapterName . ".html");
&makeproduct();
&makeproducttail();
&addTOCinfo($filename, $record[4], $record[5]);
close PRODUCT;
}
# End of Product
&makeTOCtail();
close TOC;
close subTOC;
Mi::close($db);
print "Processed $row_num records\n";
}
#------------------------------------------------------------------
# SUBROUTINES
#------------------------------------------------------------------
sub makeBullets {
local(@strings) = split(/\n/, $record[7]);
local($bullet) = 0;
foreach $string (@strings)
{
if ($string =~ s/^--/<LI>/)
{
if ($bullet == 0)
{
$string =~ s/<LI>/<UL><LI>/;
$bullet = 1;
}
}
else
{
if ($bullet == 1)
{
$string = "</UL>" . $string;
$bullet = 0;
}
}
}
$record[7] = join(/\n/, @strings);
if ($bullet == 1) # check for corner case
{
$record[7] .= "</UL>";
}
}
sub makefilename {
local(@strings) = split(/_/, @_[0]);
local($length) = @_[1];
local($new) = "";
local($first) = 1;
foreach $string (@strings)
{
if ($first == 1)
{
$new .= $string;
$first = 0;
}
else
{
$new .= "_" . $string;
}
if (length($new) > $length)
{
return $new;
}
}
return $new;
}
sub fix_special {
local($text) = @_[0];
$text =~ s/ /_/g;
$text =~ s/\!/_/g;
$text =~ s/\*/_/g;
$text =~ s/\//_/g;
$text =~ s/\&/_/g;
$text =~ s/\'/_/g;
$text =~ s/\`/_/g;
$text =~ s/#//g;
return $text;
}
#------------------------------------------------------------------
# makeproductheader
#
# subroutine makeproductheader creates header for every product file
sub makeproductheader {
local($string) = @_[0];
local($filename) = @_[1];
print PRODUCT <<PRODUCTHEADER;
<html>
<head>
<title>Solaris - $string</title>
</head>
<body>
<A HREF="http://$HOST/$HOMEHTML"><IMG SRC="/.wais/images/goto_home.gif"></A><HR>
<A HREF="http://$HOST/$HTML"><IMG SRC="/.wais/images/goto_toc.gif"> Catalyst Catalog Search Page</A> <A HREF=../$filename><IMG SRC="/.wais/images/goto_back.gif"> Sub-category</A>
<HR>
<H2><A NAME=$record[3]>"$record[3]"</A></H2>
<HR>
PRODUCTHEADER
}
#------------------------------------------------------------------
# makeproduct
#
# subroutine makeproduct creates info for every product file
sub makeproduct {
local($source) = "No";
local($address) = $record[13] . " " . $record[14] . " " . $record[15];
local($address1) = $record[16] . ", " . $record[17] . $record[18] . " " . $record[19];
local($spec) = $record[12];
local($phone) = "";
local($phone1) = "";
local($fax) = "";
local($email) = "";
local($url) = "";
local($language) = "";
if ($record[11] ne "")
{
$language = "Language: " . $record[11] . "<BR>";
}
if ($record[22] ne "")
{
$phone = "Phone: " . $record[21] . $record[22];
$phone1 = $record[23] . $record[24];
}
if ($record[26] ne "")
{
$fax = "Fax: " . $record[25] . $record[26];
}
if ($record[28] ne "")
{
$email = "Email: " . $record[27] . $record[28];
}
if ($record[29] ne "")
{
$url = "Url: " . $record[29];
}
$address =~ s/^//g;
$address1 =~ s/^//g;
$spec =~ s/\[//g;
$spec =~ s/]//g;
$spec =~ s/^ * //g;
$spec =~ s/^,//g;
if ($spec eq "")
{
$spec = "None.";
}
if ($phone1 ne "")
{
$phone .= "\n " . $phone1;
}
if ($record[10] eq "t" or $record[10] eq "T")
{
$source = "Yes";
}
print PRODUCT <<MAKEPRODUCT
<H3><A NAME=$record[4]>$record[4]</A></H3>
<H4><A NAME=$record[5]>$record[5]</A></H4>
$record[7]<p>
$language
Source Avail: $source<BR>
Product Special Handling: $spec<BR>
<HR>
<PRE>
<B>$record[5]</B>
$address
$address1
$record[20]<HR>
$phone
$fax
$email
$url
</PRE>
MAKEPRODUCT
}
#------------------------------------------------------------------
# makeproducttail
#
# subroutine makeproducttail creates tail for product file
sub makeproducttail {
print PRODUCT <<MAKEPRODUCTTAIL
</body>
</html>
MAKEPRODUCTTAIL
}
#------------------------------------------------------------------
# makeTOCheader
#
# subroutine MakeTOCheader prints header for each TOC
sub makeTOCheader {
local($filename) = @_[0];
local($category) = @_[1];
local($subcategory) = @_[2];
print TOC <<makeTOCheader
<html>
<title>Solaris - <A HREF="$filename">$subcategory</A> Products</title>
<A HREF="http://$HOST/$HOMEHTML"><IMG SRC="/.wais/images/goto_home.gif"></A><HR>
<A HREF="http://$HOST/$HTML"><IMG SRC="/.wais/images/goto_toc.gif"> Catalyst Catalog Search Page </A>
<A HREF="../$filename"><IMG SRC="/.wais/images/goto_back.gif"> Sub-category</A>
<HR>
<H1>Catalyst Solaris Products</H1>
<H2>Product Listing</H2>
<HR>
<h2><IMG SRC="/.wais/images/bullet_ball_red.gif"> <A HREF="../$filename">$subcategory</A></h2>
<ul>
makeTOCheader
}
sub addsubTOCheader {
local($category) = @_[0];
print subTOC <<addsubTOCheader
<title>Solaris - Networking</title>
<A HREF="http://$HOST/$HOMEHTML"><IMG SRC="/.wais/images/goto_home.gif"></A><HR>
<A HREF="http://$HOST/$HTML"><IMG SRC="/.wais/images/goto_toc.gif"> Catalyst Catalog Search Page</A>
<HR>
<H1>Catalyst Solaris Products</H1>
<H2>Sub-categories</H2>
<HR>
<H2><IMG SRC="/.wais/images/bullet_ball_blue.gif"> $category<H2>
<UL>
addsubTOCheader
}
sub makeTOCtail {
print subTOC <<makeTOCtail
</ul></html>
makeTOCtail
}
sub addsubTOC {
local($subcategory) = @_[0];
local($subcategoryname) = @_[1];
print subTOC <<addsubTOC
<IMG SRC="/.wais/images/bullet_ball_red.gif"><A HREF="$subcategoryname/$subcategoryname.html"><STRONG> $subcategory</A></STRONG></A><BR>
addsubTOC
}
sub addTOCinfo {
local($filename) = @_[0];
local($product) = @_[1];
local($vendor) = @_[2];
print TOC <<addTOCinfo
<B>
<IMG SRC="/.wais/images/bullet_ball_yellow.gif"> <A HREF="$filename">$product</A></B>
<ul>
$vendor</ul><p>
addTOCinfo
}